Skip to content

feat(cron): add min_interval_seconds config to prevent excessive cron scheduling#1718

Open
darrenzeng2025 wants to merge 1 commit intosipeed:mainfrom
darrenzeng2025:feat/1655-cron-min-interval
Open

feat(cron): add min_interval_seconds config to prevent excessive cron scheduling#1718
darrenzeng2025 wants to merge 1 commit intosipeed:mainfrom
darrenzeng2025:feat/1655-cron-min-interval

Conversation

@darrenzeng2025
Copy link
Contributor

Summary

This PR implements the feature requested in #1655 to add a minimum interval configuration for cron scheduling to prevent excessive task scheduling.

Changes

Configuration

  • Added MinIntervalSeconds field to CronToolsConfig struct
  • Environment variable: PICOCLAW_TOOLS_CRON_MIN_INTERVAL_SECONDS
  • Default value: 60 seconds (1 minute)
  • Value 0 disables the check

Validation Logic

  • Added validateMinInterval() function to check schedule intervals
  • For every type: directly compares every_seconds with minimum
  • For cron type: calculates the interval between next two ticks using gronx library
  • One-time schedules (at type) are not affected

Error Messages

  • Clear error messages indicating the minimum allowed interval and actual interval
  • Example: "interval too short: minimum allowed is 60 seconds, got 30 seconds"

Tests

Added comprehensive test cases in pkg/tools/cron_test.go:

  • TestCronTool_MinIntervalSeconds: validates default 60-second minimum
  • TestCronTool_MinIntervalSecondsDisabled: validates that 0 disables the check
  • TestCronTool_MinIntervalSecondsCron: validates cron expression interval checking
  • TestCronTool_AtSecondsNotAffected: validates one-time schedules are not affected
  • TestCronTool_MinIntervalSecondsCustom: validates custom minimum values
  • TestCronTool_MinIntervalSecondsNegative: validates negative values use default

Related Issue

Closes #1655

- Add MinIntervalSeconds field to CronToolsConfig (default: 60 seconds)
- Add environment variable PICOCLAW_TOOLS_CRON_MIN_INTERVAL_SECONDS
- Implement validateMinInterval() to check schedule intervals
- For 'every' type: directly compare every_seconds with minimum
- For 'cron' type: calculate next two ticks interval using gronx
- Value 0 disables the check
- Add comprehensive test cases

Closes sipeed#1655
@sipeed-bot sipeed-bot bot added type: enhancement New feature or request domain: corn domain: config dependencies Pull requests that update a dependency file labels Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file domain: config domain: corn type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add min_interval_seconds config to prevent excessive cron scheduling

1 participant